{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from __future__ import print_function\n",
    "%matplotlib inline\n",
    "import mdtraj as md"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Use two files that are distributed with MDTraj examples"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "crystal_fn = 'data/native.pdb'\n",
    "trajectory_fn = 'data/frame0.xtc'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "crystal = md.load(crystal_fn)\n",
    "trajectory = md.load(trajectory_fn, top=crystal)  # load the xtc. the crystal structure defines the topology\n",
    "trajectory"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "RMSD with exchangeable hydrogen atoms is generally not a good idea\n",
    "so let's take a look at just the heavy atoms"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "rmsds_to_crystal = md.rmsd(trajectory, crystal, 0)\n",
    "heavy_atoms = [atom.index for atom in crystal.topology.atoms if atom.element.symbol != 'H']\n",
    "heavy_rmds_to_crystal = md.rmsd(trajectory, crystal, 0, atom_indices=heavy_atoms)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from matplotlib import pyplot as plt\n",
    "plt.plot(trajectory.time, rmsds_to_crystal, 'r', label='all atom')\n",
    "plt.plot(trajectory.time, heavy_rmds_to_crystal, 'b', label='heavy atom')\n",
    "plt.legend()\n",
    "plt.title('RMSDs to crystal')\n",
    "plt.xlabel('simulation time (ps)')\n",
    "plt.ylabel('RMSD (nm)')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
